//
//  YunDanDetailHeaderView.m
//  阿帕
//
//  Created 阿帕 on 2019/12/27.
//  Copyright © 2019 GCY. All rights reserved.
//

#import "YunDanDetailHeaderView.h"

@interface YunDanDetailHeaderView ()

@property(nonatomic, strong)UILabel      *typeLabel;
@property(nonatomic, strong)UIImageView  *typeImage;
@property(nonatomic, strong)UILabel      *yunDanNumLabel;
@property(nonatomic, strong)UIImageView  *avatarView;
@property(nonatomic, strong)UILabel      *nicknameLabel;
@property(nonatomic, strong)GQRatingView *ratingView;
@property(nonatomic, strong)UILabel      *ratingNumLabel;
@property(nonatomic, strong)UILabel      *historyOrderNumLabel;
@property(nonatomic, strong)UIButton     *plateNumButton;

@property(nonatomic, assign)NSInteger takeOrderType;
@property(nonatomic, strong)NSString *vehicleCode;

@end


@implementation YunDanDetailHeaderView

#pragma mark - Intial
//- (instancetype)initWithFrame:(CGRect)frame {
//    return [self initWithFrame:frame takeOrderType:0];
//}

- (instancetype)initWithFrame:(CGRect)frame takeOrderType:(NSInteger)takeOrderType Dict:(nonnull NSDictionary *)dic{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self setUpUIWithTakeOrderType:takeOrderType Dict:dic];
    }
    return self;
}

- (void)setUpUIWithTakeOrderType:(NSInteger)takeOrderType Dict:(NSDictionary *)dic{
    self.takeOrderType = takeOrderType;
    self.backgroundColor = BackgroundColor;
    
    _typeImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, ScreenW, 65)];
    _typeImage.image = image(@"gcy_img_ydzxd_daijiesuan");
    [self addSubview:_typeImage];
    
    _typeLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, 0, 100, _typeImage.cy_height)];
    _typeLabel.textColor = [UIColor whiteColor];
    _typeLabel.font = font(19);
    _typeLabel.text = @"- - -";
    [_typeImage addSubview:_typeLabel];
    
    // 2k接单
    UIView *chooseVehicleView = [[UIView alloc] initWithFrame:CGRectMake(0, 65, ScreenW, takeOrderType == 2 ? 40 : 0)];
    chooseVehicleView.backgroundColor = UIColor.whiteColor;
    chooseVehicleView.hidden = takeOrderType != 2;
    [self addSubview:chooseVehicleView];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(15, 5, 100, 40)];
    label.textColor = Dark_TextColor;
    label.text = @"选择车辆";
    label.font = font(14);
    label.adjustsFontSizeToFitWidth = YES;
    [chooseVehicleView addSubview:label];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setTitleColor:Dark_TextColor forState:UIControlStateNormal];
    [button setTitle:@"请选择承运车辆" forState:UIControlStateNormal];
    button.titleLabel.font = font(14);
    button.frame = CGRectMake(70, 5, ScreenW-95, 40);
    [button setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];
    [button addTarget:self action:@selector(chooseVehicleAction:) forControlEvents:UIControlEventTouchUpInside];
    [chooseVehicleView addSubview:button];
    
    if (self.vehicleArr.count > 0) {
        DriverVehicleModel *vehicle = [self.vehicleArr firstObject];
        [button setTitle:vehicle.licenseNumber forState:UIControlStateNormal];
        self.vehicleCode = vehicle.code;
    }
    
    UIImageView *arrowIV = [[UIImageView alloc] initWithFrame:CGRectMake(button.cy_right, 0, 20, 20)];
    [arrowIV setImage:[UIImage imageNamed:@"gcy_btn_my_rArrow"]];
    [chooseVehicleView addSubview:arrowIV];
    arrowIV.centerY = button.centerY;
    
    UIView *jiedanView = [[UIView alloc] initWithFrame:CGRectMake(0, chooseVehicleView.bottom, ScreenW, takeOrderType == 0 ? 0 : 60)];
    jiedanView.backgroundColor = UIColor.whiteColor;
    jiedanView.hidden = takeOrderType == 0;
    [self addSubview:jiedanView];
    
    UIButton *jiedanButton = [UIButton buttonWithType:UIButtonTypeCustom];
    cut(jiedanButton, BTN_BORDER_RADIUS);
    [jiedanButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    jiedanButton.backgroundColor = Theme_ColorValue;
    [jiedanButton setTitle:@"接单" forState:UIControlStateNormal];
    jiedanButton.titleLabel.font = font(16);
    jiedanButton.frame = CGRectMake(15, 10, ScreenW - 30, 40);
    [jiedanButton addTarget:self action:@selector(takeOrderAction:) forControlEvents:UIControlEventTouchUpInside];
    [jiedanView addSubview:jiedanButton];
    
    
    UIView *yunDanBgView = [[UIView alloc] initWithFrame:CGRectMake(0, takeOrderType == 0 ? _typeImage.cy_bottom : jiedanView.bottom + 10, ScreenW, 45)];
    yunDanBgView.backgroundColor = [UIColor whiteColor];
    [self addSubview:yunDanBgView];
    
    //运单号
    _yunDanNumLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, ScreenW-20, 45)];
    _yunDanNumLabel.textColor = Dark_TextColor;
    _yunDanNumLabel.backgroundColor = [UIColor whiteColor];
    _yunDanNumLabel.font = font(16);
    _yunDanNumLabel.text = @"运输单号：-";
    //    [DCSpeedy dc_setUpLabel:_yunDanNumLabel Content:_yunDanNumLabel.text IndentationFortheFirstLineWith:15];
    _yunDanNumLabel.adjustsFontSizeToFitWidth = YES;
    [yunDanBgView addSubview:_yunDanNumLabel];
    
#pragma mark - 像、昵称、评分等区域 150
    //头像
    float width = (ScreenW-30-30)/3;
    NSArray *fillImageInfoList = dic[@"fillImageInfoList"];
    NSArray * signImageInfoList = dic[@"signImageInfoList"];
    NSMutableArray *muArr = [NSMutableArray array];
    [fillImageInfoList enumerateObjectsUsingBlock:^(NSString *obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if ([DCSpeedy isBlankString:obj] == NO) {
            [muArr addObject:obj];
        }
    }];
    NSMutableArray *muArr1 = [NSMutableArray array];
    [signImageInfoList enumerateObjectsUsingBlock:^(NSString *obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if ([DCSpeedy isBlankString:obj] == NO) {
            [muArr1 addObject:obj];
        }
    }];
    float a = 0;
    float b = 0;
    if (muArr.count == 0) {
        a = ((float)width * ((int)muArr.count / 3));
    }else{
        a = ((float)width * ((int)muArr.count / 3 + 1));
    }
    if (muArr1.count == 0) {
        b = ((float)width * ((int)muArr1.count / 3));
    }else{
        b = ((float)width * ((int)muArr1.count / 3 + 1));
    }
    float c = 0;
    if ([_infoDetailDic[@"orderDetail"][@"status"] intValue] == 1) {
        //待运输
        c = 0;
    } else {
        c = 35;
    }
    UIView *headBgView = [[UIView alloc] initWithFrame:CGRectMake(0, yunDanBgView.cy_bottom + 10, ScreenW, 165 + a + b + c)];
    headBgView.tag = 100;
    headBgView.backgroundColor = [UIColor whiteColor];
    [self addSubview:headBgView];
    
    //头像
    _avatarView = [[UIImageView alloc] initWithFrame:CGRectMake(15, 10, 40, 40)];
    _avatarView.image = image(@"gcy_img_siji_dHead");
    cut(_avatarView, 20);
    [headBgView addSubview:_avatarView];
    
    //昵称
    _nicknameLabel = [[UILabel alloc] initWithFrame:CGRectMake(_avatarView.cy_right + 5, _avatarView.top, 70, 20)];
    _nicknameLabel.textColor = Dark_TextColor;
    _nicknameLabel.font = font(16);
    _nicknameLabel.text = @"-";
    [headBgView addSubview:_nicknameLabel];
    
    //历史订单数量
    _historyOrderNumLabel = [[UILabel alloc] initWithFrame:CGRectMake(_nicknameLabel.left, _nicknameLabel.cy_bottom + 5, 90, 20)];
    _historyOrderNumLabel.textColor = Light_TextColor;
    _historyOrderNumLabel.font = font(12);
    _historyOrderNumLabel.text = @"历史订单：-单";
    _historyOrderNumLabel.adjustsFontSizeToFitWidth = YES;
    [headBgView addSubview:_historyOrderNumLabel];
    
    //车牌
    _plateNumButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_plateNumButton setTitleColor:Dark_TextColor forState:UIControlStateNormal];
    [_plateNumButton setTitle:@"-" forState:UIControlStateNormal];
    _plateNumButton.titleLabel.font = font(12);
    [_plateNumButton setTitleColor:Light_TextColor forState:UIControlStateNormal];
    _plateNumButton.frame = CGRectMake(_historyOrderNumLabel.cy_right + 10, _historyOrderNumLabel.top, 120, 20);
    [_plateNumButton setImage:image(@"gcy_icon_siji_chepai") forState:UIControlStateNormal];
    [headBgView addSubview:_plateNumButton];
    
    [_plateNumButton layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft imageTitleSpace:5];
    
    //装车单、卸车单、运输单轨迹
    NSArray *titleArr;
    if ([_infoDetailDic[@"orderDetail"][@"status"] intValue] == 1) {
        //待运输
        titleArr = @[@"装车磅单", @"运输单轨迹"];
    } else {
        titleArr = @[@"装车磅单", @"卸车磅单", @"运输单轨迹"];
    }
    CGFloat zhImagHeight = 0;
    CGFloat xhImagHeight = 0;
    for (int i=0; i<titleArr.count; i++) {
        UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, _avatarView.cy_bottom + 10 + 15 * i  + 35*i + zhImagHeight + xhImagHeight, ScreenW, 35)];
        bgView.tag = 500 + i;
        bgView.backgroundColor = [UIColor whiteColor];
        bgView.userInteractionEnabled = YES;
        [headBgView addSubview:bgView];
        
        [bgView nyl_addTapGes:^{
            if (self.delegate && [self.delegate respondsToSelector:@selector(tableHeaderViewClickEvent:andTitle:)]) {
                [self.delegate tableHeaderViewClickEvent:bgView.tag andTitle:titleArr[i]];
            }
        }];
        
        UILabel *typeLabel = [[UILabel alloc] initWithFrame:CGRectMake(_avatarView.left, 0, 100, bgView.cy_height)];
        typeLabel.textColor = Dark_TextColor;
        typeLabel.font = font(13);
        typeLabel.text = titleArr[i];
        [bgView addSubview:typeLabel];
        
        UIImageView *rArrow = [[UIImageView alloc] initWithFrame:CGRectMake(bgView.cy_right-25, 15, 6, 10)];
        rArrow.image = image(@"gcy_icon_my_rArrow");
        [bgView addSubview:rArrow];
        
        UIView *line = [[UIView alloc] initWithFrame:CGRectMake(15, bgView.cy_height-1, ScreenW-30, 1)];
        line.backgroundColor = BackgroundColor;
        [bgView addSubview:line];
        if (i < 2 ) {
            //装卸磅单图片
            NSArray *fillImageInfoList = dic[@"fillImageInfoList"];
            NSArray * signImageInfoList = dic[@"signImageInfoList"];
            NSMutableArray *muArr = [NSMutableArray array];
            [fillImageInfoList enumerateObjectsUsingBlock:^(NSString *obj, NSUInteger idx, BOOL * _Nonnull stop) {
                if ([DCSpeedy isBlankString:obj] == NO) {
                    [muArr addObject:obj];
                }
            }];
            NSMutableArray *muArr1 = [NSMutableArray array];
            [signImageInfoList enumerateObjectsUsingBlock:^(NSString *obj, NSUInteger idx, BOOL * _Nonnull stop) {
                if ([DCSpeedy isBlankString:obj] == NO) {
                    [muArr1 addObject:obj];
                }
            }];
            UIView *zcView = [[UIView alloc] init];
            NSMutableArray *imgArr = [@[] mutableCopy];
            if ([CJStringWithFormat(@"%@",titleArr[i]) isEqualToString:@"装车磅单"]) {
                imgArr = muArr;
            }else{
                imgArr = muArr1;
            }
            for (int j=0; j< imgArr.count; j++) {
                
                int x = j%3;
                int y = j/3;
                
                float width = (ScreenW-30-30)/3;
                
                UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake((width + 15)*x , (width + 15)*y, width, width)];
                imageView.contentMode = UIViewContentModeScaleAspectFill;
                imageView.clipsToBounds = YES;
                setNetImage(imageView, imgArr[j], @"gcy_icon_plaholder");
                imageView.userInteractionEnabled = YES;
                [imageView nyl_addTapGes:^{
                    HZPhotoBrowser *browser = [[HZPhotoBrowser alloc] init];
                    browser.isFullWidthForLandScape = YES;
                    browser.isNeedLandscape = YES;
                    browser.currentImageIndex = j;
                    browser.imageArray = imgArr;
                    [browser show];
                }];
                [zcView addSubview:imageView];
                if ([CJStringWithFormat(@"%@",titleArr[i]) isEqualToString:@"装车磅单"]) {
                    zhImagHeight = ((width)*(y+1)) ;
                }else{
                    xhImagHeight = ((width)*(y+1));
                }
                zcView.frame = CGRectMake(0, bgView.cy_bottom, ScreenW, (width) * (y+1));
                [headBgView addSubview:zcView];

            }
        }
        
    }
    
#pragma mark - 地址区域 180
    UIView *addressBgView = [[UIView alloc] initWithFrame:CGRectMake(0, headBgView.cy_bottom, ScreenW, 180)];
    addressBgView.backgroundColor = [UIColor whiteColor];
    [self addSubview:addressBgView];
    
    NSArray *zhuangXieTuArr = @[@"gcy_icon_main_zhuang",@"gcy_icon_main_xie"];
    for (int i=0; i<zhuangXieTuArr.count; i++) {
        UIButton *adresBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [adresBtn setTitleColor:Dark_TextColor forState:UIControlStateNormal];
        [adresBtn setTitle:@"-" forState:UIControlStateNormal];
        adresBtn.tag = 20+i;
        adresBtn.titleLabel.font = font(13);
        adresBtn.titleLabel.numberOfLines = 2;
        adresBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        [adresBtn setTitleColor:Dark_TextColor forState:UIControlStateNormal];
        adresBtn.frame = CGRectMake(15, 40*i, addressBgView.width-30, 40);
        [adresBtn setImage:image(zhuangXieTuArr[i]) forState:UIControlStateNormal];
        [addressBgView addSubview:adresBtn];
        [adresBtn layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft imageTitleSpace:5];
    }
    
    //分割线
    UIView *hLine = [[UIView alloc] initWithFrame:CGRectMake(15, 79, ScreenW-30, 1)];
    hLine.backgroundColor = BackgroundColor;
    [addressBgView addSubview:hLine];
    
    UIView *hLine2 = [[UIView alloc] initWithFrame:CGRectMake(15, addressBgView.height-1, ScreenW-30, 1)];
    hLine2.backgroundColor = BackgroundColor;
    [addressBgView addSubview:hLine2];
    
    //发货人、收货人等
    NSArray *fahuoTArr = @[@"发货人:",@"发货电话:",@"收货人:",@"收货电话:"];
    for (int i=0; i<fahuoTArr.count; i++) {
        int x = i%2;
        int y = i/2;
        UILabel *textLabel = [[UILabel alloc] initWithFrame:CGRectMake(15+x*ScreenW/2, 80+30*y, 55, 30)];
        textLabel.textColor = Light_TextColor;
        textLabel.font = font(13);
        textLabel.text = fahuoTArr[i];
        textLabel.adjustsFontSizeToFitWidth = YES;
        [addressBgView addSubview:textLabel];
        
        //值
        UILabel *valueLabel = [[UILabel alloc] initWithFrame:CGRectMake(textLabel.cy_right, textLabel.top, ScreenW/2-75, textLabel.cy_height)];
        valueLabel.textColor = Dark_TextColor;
        valueLabel.font = font(13);
        valueLabel.tag = 50 + i;
        valueLabel.text = @"-";
        [addressBgView addSubview:valueLabel];
        if (x == 1) {
            textLabel.hidden = YES;
            valueLabel.hidden = YES;
        }
    }
    
    //导航按钮
    UIButton *navButton = [UIButton buttonWithType:UIButtonTypeCustom];
    navButton.tag = 66;
    [navButton setTitleColor:Theme_ColorValue forState:UIControlStateNormal];
    [navButton setTitle:@"查看路线 >" forState:UIControlStateNormal];
    navButton.titleLabel.font = font(14);
    navButton.titleLabel.adjustsFontSizeToFitWidth = YES;
    navButton.frame = CGRectMake(ScreenW-150-15, addressBgView.height -40 , 150, 40);
    navButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    [navButton addTarget:self action:@selector(btnTypeClick:) forControlEvents:UIControlEventTouchUpInside];
    [addressBgView addSubview:navButton];
}

- (void)btnTypeClick:(UIButton *)button {
    if (self.delegate && [self.delegate respondsToSelector:@selector(tableHeaderViewClickEvent:andTitle:)]) {
        [self.delegate tableHeaderViewClickEvent:button.tag andTitle:button.titleLabel.text];
    }
}

- (void)setInfoDetailDic:(NSDictionary *)infoDetailDic {
    
    UIView *headBgView = [self viewWithTag:100];
    
    _infoDetailDic = infoDetailDic;
    
    //    status (integer, optional): 运单状态：0未接单/1已接单/2已装货/3已卸货/4已结算/5已打款 ,
    NSInteger status = [infoDetailDic[@"orderDetail"][@"status"] integerValue];
    
    if (status == 1 || status == 2) {
        for (int i=0; i<3; i++) {
            UIView *oldBgView = [self viewWithTag:500 + i];
            oldBgView.hidden = YES;
        }
        //装车单、卸车单、运输单轨迹
        //装卸磅单图片
        CGFloat zhImagHeight = 0.00;
    
        NSArray *titleArr = @[@"装车磅单", @"运输单轨迹"];
        for (int i=0; i<titleArr.count; i++) {
            UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, _avatarView.cy_bottom + 10 + 52.5f*i + zhImagHeight, ScreenW, 52.5f)];
            bgView.tag = 500 + i;
            bgView.backgroundColor = [UIColor whiteColor];
            bgView.userInteractionEnabled = YES;
            [headBgView addSubview:bgView];
            if (i == 1) {
                bgView.tag = 502;
            }
            [bgView nyl_addTapGes:^{
                if (self.delegate && [self.delegate respondsToSelector:@selector(tableHeaderViewClickEvent:andTitle:)]) {
                    [self.delegate tableHeaderViewClickEvent:bgView.tag andTitle:titleArr[i]];
                }
            }];
            
            UILabel *typeLabel = [[UILabel alloc] initWithFrame:CGRectMake(_avatarView.left, 0, 100, bgView.cy_height)];
            typeLabel.textColor = Dark_TextColor;
            typeLabel.font = font(13);
            typeLabel.text = titleArr[i];
            [bgView addSubview:typeLabel];
            
            UIImageView *rArrow = [[UIImageView alloc] initWithFrame:CGRectMake(bgView.cy_right-25, 21.25f, 6, 10)];
            rArrow.image = image(@"gcy_icon_my_rArrow");
            [bgView addSubview:rArrow];
            
            UIView *line = [[UIView alloc] initWithFrame:CGRectMake(15, bgView.cy_height-1, ScreenW-30, 1)];
            line.backgroundColor = BackgroundColor;
            [bgView addSubview:line];
            NSArray *fillImageInfoList = infoDetailDic[@"fillImageInfoList"];
            for (int j=0; j< fillImageInfoList.count; j++) {
                int y = j/3;
                float width = (ScreenW-30-30)/3;
                zhImagHeight = ((width)*(y+1));
            }
        }
    }
    
    if (status == 1) {
        
        _typeImage.image = image(@"gcy_img_ydzxd_daiyunshu");
        _typeLabel.text = @"待运输";
        
    } else if (status == 2) {
        
        _typeImage.image = image(@"gcy_img_ydzxd_yunshuzhong");
        _typeLabel.text = @"运输中";
        
    } else if (status == 3) {
        
        _typeImage.image = image(@"gcy_img_ydzxd_daijiesuan");
        _typeLabel.text = @"待结算";
        
    } else if (status == 4) {
        
        _typeImage.image = image(@"gcy_img_ydzxd_daidakuan");
        _typeLabel.text = @"待打款";
        
    } else if (status == 5) {
        
        _typeImage.image = image(@"gcy_img_ydzxd_yiwancheng");
        _typeLabel.text = @"已完成";
    }
    
    _yunDanNumLabel.text = CJStringWithFormat(@"运输单号：%@",infoDetailDic[@"orderDetail"][@"orderCode"]);
    
    //    [DCSpeedy dc_setUpLabel:_yunDanNumLabel Content:_yunDanNumLabel.text IndentationFortheFirstLineWith:15];
    
    NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] initWithString:_yunDanNumLabel.text];
    [attString addAttribute:(NSString*)NSForegroundColorAttributeName value:Dark_TextColor range:[_yunDanNumLabel.text rangeOfString:@"运输单号："]];
    [attString addAttribute:(NSString*)NSForegroundColorAttributeName value:Theme_ColorValue range:[_yunDanNumLabel.text rangeOfString:infoDetailDic[@"orderDetail"][@"orderCode"]]];
    [_yunDanNumLabel setAttributedText:attString];
    
    
    
    setNetImage(_avatarView, infoDetailDic[@"orderDetail"][@"driverHeadImg"], @"gcy_img_my_defultHead");
    
    CGSize size = [DCSpeedy dc_calculateTextSizeWithText:infoDetailDic[@"orderDetail"][@"driverName"] WithTextFont:16 WithMaxW:1000];
    _nicknameLabel.text = infoDetailDic[@"orderDetail"][@"driverName"];
    _nicknameLabel.cy_width = size.width + 10;
    
    float score = 0.0;
    
    if ([DCSpeedy isBlankString:CJStringWithFormat(@"%@",infoDetailDic[@"orderDetail"][@"driverAverage"])] == NO) {
        score = [infoDetailDic[@"orderDetail"][@"driverAverage"] floatValue];
    }
    
    //星级 [NSNumber numberWithInt:_model.avgBasicGrade] [NSNumber numberWithFloat:_model.avgBasicGrade]
    _ratingView = [GQRatingView init]
    .frameChain(CGPointMake(30 + 40 + size.width, _nicknameLabel.top + 2.5),15)
    .canTouchChain(NO)
    .needIntValueChain(YES)
    .scoreNumChain([NSNumber numberWithFloat:score])
    .normalColorChain([UIColor cy_colorWithHexString:@"#C0CDDE"])
    .highlightColorChian([UIColor cy_colorWithHexString:@"#FFC000"])
    .scroreBlockChain(^(NSNumber *scoreNumber){
    }).superViewChain(headBgView);
    
    _ratingNumLabel = [[UILabel alloc] initWithFrame:CGRectMake(_ratingView.cy_right + 5, _avatarView.top, 50, 20)];
    _ratingNumLabel.textColor = Light_TextColor;
    _ratingNumLabel.font = font(13);
    _ratingNumLabel.text = CJStringWithFormat(@"%.1f", score);
    [headBgView addSubview:_ratingNumLabel];
    
    _historyOrderNumLabel.text = [DCSpeedy isBlankString:CJStringWithFormat(@"%@", infoDetailDic[@"orderDetail"][@"driverHistoryCount"])] == YES ? @"历史订单：0单" : CJStringWithFormat(@"历史订单：%@单", infoDetailDic[@"orderDetail"][@"driverHistoryCount"]);
    
    
    [_plateNumButton setTitle:infoDetailDic[@"orderDetail"][@"vehicleLicense"] forState:UIControlStateNormal];
    
    NSArray *adresArr = @[CJStringWithFormat(@"%@%@", infoDetailDic[@"order"][@"shipperAddress"], infoDetailDic[@"order"][@"shipperDetailAddress"]),
                          CJStringWithFormat(@"%@%@", infoDetailDic[@"order"][@"consigneeAddress"], infoDetailDic[@"order"][@"consigneeDetailAddress"])];
    for (int i=0; i<adresArr.count; i++) {
        UIButton *button = [self viewWithTag:20+i];
        [button setTitle:adresArr[i] forState:UIControlStateNormal];
    }
    
    
    NSArray *phoneArr = @[[NSString nullToString:CJStringWithFormat(@"%@", infoDetailDic[@"order"][@"shipperName"])],
                          [NSString nullToString:CJStringWithFormat(@"%@", infoDetailDic[@"order"][@"shipperPhone"])],
                          [NSString nullToString:CJStringWithFormat(@"%@", infoDetailDic[@"order"][@"consigneeName"])],
                          [NSString nullToString:CJStringWithFormat(@"%@", infoDetailDic[@"order"][@"consigneePhone"])],
    ];
    for (int i=0; i<phoneArr.count; i++) {
        UILabel *label = [self viewWithTag:50+i];
        label.text = phoneArr[i];
    }
}

/// 选择车辆
- (void)chooseVehicleAction:(UIButton *)sender {
    NSMutableArray *arr = [NSMutableArray array];
    for (DriverVehicleModel *model in self.vehicleArr) {
        [arr addObject:model.licenseNumber];
    }
    
    BRStringPickerView *stringPickerView = [[BRStringPickerView alloc] initWithPickerMode:BRStringPickerComponentSingle];
    stringPickerView.title = @"选择承运车辆";
    stringPickerView.dataSourceArr = arr;
    stringPickerView.resultModelBlock = ^(BRResultModel *resultModel) {
        DriverVehicleModel *vehicle = self.vehicleArr[resultModel.index];
        self.vehicleCode = vehicle.code;
    };
    
    BRPickerStyle *customStyle = [BRPickerStyle pickerStyleWithThemeColor:Theme_ColorValue];
    customStyle.topCornerRadius = 7;
    stringPickerView.pickerStyle = customStyle;
    [stringPickerView show];
}

/// 接单
- (void)takeOrderAction:(UIButton *)sender {
    if (self.delegate && [self.delegate respondsToSelector:@selector(jiedanBtnClickEvent:vehicleCode:)]) {
        [self.delegate jiedanBtnClickEvent:self.takeOrderType vehicleCode:self.vehicleCode];
    }
}

@end
